#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <pthread.h>
#include <thread>

int* addr = nullptr;

void* start1(void* args)
{
    std::string name = static_cast<const char*>(args);
    int a = 100;
    addr = &a;
    while(true)
    {
        std::cout << name << " local val a: " << a << std::endl;
        sleep(1);
    }
}

void* start2(void* args)
{
    std::string name = static_cast<const char*>(args);
    while(true)
    {
        if(addr != nullptr)
        {
            std::cout << name << " mod val a: " << (*addr)++ << std::endl;
        }
        sleep(1);
    }
}

int main()
{
    pthread_t tid1,tid2;
    pthread_create(&tid1,nullptr,start1,(void*)"thread-1");
    pthread_create(&tid2,nullptr,start2,(void*)"thread-2");
    pthread_join(tid1,nullptr);
    pthread_join(tid2,nullptr);
    return 0;
}
